package logic

import (
	"context"
	"wechat/userrpc/userrpc"

	"wechat/api/internal/svc"
	"wechat/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FriendAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFriendAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FriendAddLogic {
	return &FriendAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FriendAddLogic) FriendAdd(req *types.FriendAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.UserRpc.AddFriend(l.ctx, &userrpc.AddFriendRequest{
		UserId:  req.UserId,
		Account: req.Account,
		Context: req.Context,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "申请好友成功",
		Code:    200,
		Data:    add,
	}, nil
}
